package org.teachertools.web.controller;

import org.apache.commons.lang.StringUtils;
import org.springframework.validation.Errors;
import org.springframework.validation.Validator;
import org.teachertools.data.Eleve;

public class EleveValidator implements Validator {

	@Override
	public boolean supports(Class clazz) {
		return Eleve.class.isAssignableFrom(clazz);
	}

	@Override
	public void validate(Object obj, Errors errors) {
		Eleve eleve = (Eleve) obj;
		if (StringUtils.isEmpty(eleve.getNom()) && StringUtils.isEmpty(eleve.getPrenom())
				&& StringUtils.isEmpty(eleve.getClasse())) {
			errors.reject("error.form.empty");
		}
	}

}
